package com.ht.demo.admin.controller.monitor;

import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.enums.OperateTypeEnum;
import com.ht.demo.service.annotation.LoggerInfo;

import com.ht.demo.common.pojo.qto.monitor.LoginInfoQTO;
import com.ht.demo.service.annotation.Permission;
import com.ht.demo.service.manager.monitor.LoginInfoManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统登录日志，登录记录Controller
 * 
 * @author hdengxian
 * @date 2023-07-31
 */

@RestController
@RequestMapping("${basePath}")
public class LoginInfoController {
    @Resource
    private LoginInfoManager loginInfoManager;

    /**
     * 系统登录日志，登录记录
     * 删除
     */
    @Permission(permissionId = "monitor:loginInfo:delete", desc = "删除")
    @LoggerInfo(title = "删除", operateType = OperateTypeEnum.DELETE)
    @GetMapping("/loginInfo/removeById")
    public ResultData deleteById(Long id){
        return new ResultData<>(loginInfoManager.deleteById(id));
    }

    /**
     * 系统登录日志，登录记录
     * 删除
     */
    @Permission(permissionId = "monitor:loginInfo:delete", desc = "删除")
    @LoggerInfo(title = "删除", operateType = OperateTypeEnum.DELETE)
    @GetMapping("/loginInfo/removeByIds/{ids}")
    public ResultData deleteByIds(@PathVariable Long[] ids){
        return new ResultData<>(loginInfoManager.deleteByIds(ids));
    }

    @Permission(permissionId = "monitor:loginInfo:clean")
    @LoggerInfo(title = "清空所有登录记录", operateType = OperateTypeEnum.DELETE)
    @GetMapping("/loginInfo/clean")
    public ResultData cleanAll() {
        return new ResultData(loginInfoManager.cleanAll());
    }

    @Permission(permissionId = "monitor:loginInfo:forceQuit")
    @LoggerInfo(title = "强制退出登录", operateType = OperateTypeEnum.FORCE)
    @GetMapping("/loginInfo/forceQuit")
    public ResultData forceQuit(String token) {
        return new ResultData(loginInfoManager.forceQuit(token));
    }

    /**
     * 系统登录日志，登录记录
     * 查询列表
     */
    @Permission(permissionId = "monitor:loginInfo:list")
    @PostMapping("/loginInfo/getForPage")
    public ResultData getForPage(@RequestBody LoginInfoQTO qto) {
        return new ResultData<>(loginInfoManager.findDataForPage(qto));
    }

    /**
     * 系统登录日志，登录记录
     * 获取详细信息
     */
    @GetMapping(value = "/loginInfo/getDetailById")
    public ResultData getDetailById(Long id) {
        return new ResultData(loginInfoManager.findById(id));
    }


}
